<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="cn.company.bean.Culture"%>
<%@page import="cn.company.database.DBUtils"%>
<%@page import="cn.company.bean.Sort"%>
<%@page import="cn.company.bean.SubSort"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网站后台管理系统</title>
<%
	String path = request.getContextPath();
	List<Culture> cultures = DBUtils.getCultrues();
	List<Sort> sorts = DBUtils.getSortsByModuleId(4);
	List<SubSort> subsorts = DBUtils.getSubSorts();
	int id = 0;
%>
<script language="javascript" src="<%=path %>/OurHome/images/jquery.js"></script>
<link href="<%=path %>/OurHome/css/index.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript">
	function callback(msg){
		 document.getElementById("msg").innerHTML = msg;  
		 document.getElementById("path").value=msg;
	}
	
	function CreateXmlHttp() { 
		var xmlhttp = false;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		    try {
			    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		    } catch (e2) {
			    xmlhttp = false;
		    }
		}
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		var data = document.getElementById("sortid").value;   
		if(!xmlhttp) { 
	         alert("创建xmlhttp对象异常！"); 
	         return false; 
	    }   
	    xmlhttp.open("POST",location.href.substring(0, location.href.lastIndexOf('/'))+"/subsortservlet.jsp?data="+data,false); 
		xmlhttp.onreadystatechange = function() {   
			if(xmlhttp.readyState == 4) { 
				if(xmlhttp.status == 200){ 
					var jsons = eval('('+xmlhttp.responseText+')');
					if(jsons.length == 0){
						document.form2.subsortid.options[0] = new Option("==请选择==","");
					}else{
						for(i = 0;i < jsons.length;i++){
							document.form2.subsortid.options[i] = new Option(jsons[i].subsortname,jsons[i].subsortid);
						}
						for(i = 0;i < jsons.length;i++){
							document.form2.subsortid.options[i] = new Option(jsons[i].subsortname,jsons[i].subsortid);
						}
					}
	            }      
	        } 
	    };
	    xmlhttp.send(); 
	}  
</script>
</head>
<body>
	<div id="mainDiv">
		<c:import url="../public/top.jsp" />
		<div id="centerDiv">
			<c:import url="../public/navigation.jsp"></c:import>
			<div id="right"> 
				<div id="current">&nbsp;&nbsp;&nbsp;&nbsp;当前位置: 企业文化管理</div>
				<div id="form">
					<P>&nbsp;</P>
					<fieldset>
						<legend>添加子分类:</legend>
						<form action="<%=path %>/OurHomeControlServlet" method="post">
							<input type="hidden" name="action" value="addsubsort" />
							子分类名称:<input type="text" name="subsortname" /><br />
							所属分类:
							<select name="sortid">
								<%
									for(int i = 0;i < sorts.size();i++){
								%>
										<option value="<%=sorts.get(i).getId() %>"><%=sorts.get(i).getSortName() %></option>
								<%
									}
								%>
							</select><br>
							<input type="submit" value="提交内容" id="submit" name="submit"/>
							<P>&nbsp;</P>
						</form>
						<table border="1" cellpadding="0" cellspacing="0" style="border-color:#000000;">
								<tr bgcolor="#e8e8e0">
									<td width="30">编号</td>
									<td width="100">标题</td>
									<td width="100">所属分类</td>
									<td width="50" align="center">删除</td>
								</tr>
								<%
									for(int i = 0;i < subsorts.size();i++){
									%>
									<tr>
										<td><%=i + 1 + "、" %></td>
										<td><%=subsorts.get(i).getSubsortName() %></td>
										<td><%=DBUtils.getSortNameById(subsorts.get(i).getSortid()) %></td>
										<td align="center"><a href="<%=path %>/OurHome/delete.jsp?table=subsort&id=<%=subsorts.get(i).getId() %>&redirect=<%=path %>/OurHome/culture/company_culture.jsp">删除</a></td>
									</tr>
									<%
									}
								%>
							</table>
						<P>&nbsp;</P>
					</fieldset>
					
<%/***************************************************************************************************华丽的分割线***********************************************************************************************************************/ %>		
					
					
					<P>&nbsp;</P>
					<fieldset>
						<legend>添加文章:</legend>
						<form action="<%=path %>/OurHome/uploadAttaches.jsp" method="post" enctype="multipart/form-data" target="uploadIframe">
							类型图片：<input type="file" name="upload"/>
							<input type="submit" value="上传"/><br>
							<span id="msg"></span>
						</form>
						<iframe name="uploadIframe" id="uploadIframe" style="display:none"></iframe>
						<form action="<%=path %>/OurHomeControlServlet" method="post" name="form2" id="form2">
							<input type="hidden" name="action" value="addculture" />
							<input type="hidden" name="path" id="path"/>
							标题：<input type="text" name="topic" /><br />
							时间：<input type="text" name="time" />格式：（2010-08-08）<br />
							分类:
							<select name="sortid" id="sortid" onchange="CreateXmlHttp()">
								<option selected="selected">==请选择==</option>
								<%
									for(int i = 0;i < sorts.size();i++){
								%>
										<option value="<%=sorts.get(i).getId() %>"><%=sorts.get(i).getSortName() %></option>
								<%
									}
								%>
							</select>
							<select name="subsortid" id="subsortid">
							</select><br>
							内容：<c:import url="../../jsp/demo2.jsp"></c:import>
							<input type="submit" value="提交内容" id="submit" name="submit"/>
						</form>
					</fieldset>
					<P>&nbsp;</P>
					<table border="1" cellpadding="0" cellspacing="0" style="border-color:#000000;">
						<tr bgcolor="#e8e8e0">
							<td width="30">编号</td>
							<td width="100">标题</td>
							<td width="100">所属分类</td>
							<td width="100">日期</td>
							<td width="100">图片路径</td>
							<td width="50" align="center">修改</td>
							<td width="50" align="center">删除</td>
						</tr>
						<%
							for(int i = 0;i < cultures.size();i++){
							%>
							<tr>
								<td><%=i + 1 + "、" %></td>
								<td><%=cultures.get(i).getTopic() %></td>
								<td><%=DBUtils.getSubSortNameById(cultures.get(i).getSortid()) %></td>
								<td><%=cultures.get(i).getTime() %></td>
								<td><%=cultures.get(i).getImagepath() %></td>
								<td align="center"><a href="<%=path %>/OurHome/culture/update_company_culture.jsp?id=<%=cultures.get(i).getId() %>">修改</a></td>
								<td align="center"><a href="<%=path %>/OurHome/delete.jsp?table=culture&id=<%=cultures.get(i).getId() %>&redirect=<%=path %>/OurHome/culture/company_culture.jsp">删除</a></td>
							</tr>
							<%
							}
						%>
					</table>
					<p>&nbsp;</p>
				</div>
			</div>
		</div>
		<div id="bottomDiv"></div>
	</div>
	<script language="javascript">
		$("#test1").toggle(function(){$("#test").slideDown();},function(){$("#test").slideUp();});
	</script>
</body>
<%!
	private String htmlspecialchars(String str) {
		str = str.replaceAll("&", "&amp;");
		str = str.replaceAll("<", "&lt;");
		str = str.replaceAll(">", "&gt;");
		str = str.replaceAll("\"", "&quot;");
		return str;
	}
%>
</html>
